package com.cgly.medical.controller;

import com.cgly.medical.service.DrugCompanyService;
import com.cgly.medical.domain.DrugCompany;
import com.cgly.medical.util.Msg;
import cn.hutool.core.date.DateTime;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin  //解决跨域问题
public class DrugCompanyController {

    @Autowired
    private DrugCompanyService drugCompanyService;

    @GetMapping("/drugCompany/getall")
    public Msg getAllDrugCompany1(){
        Msg msg = drugCompanyService.selectAllDrugCompany1();
        return msg;
    }

    @GetMapping("/drugCompany/getall/{page}/{limit}")
    public Msg getAllDrugCompany(@PathVariable Integer page, @PathVariable Integer limit){
        Msg msg = drugCompanyService.selectAllDrugCompany(page,limit);
        return msg;
    }

    @GetMapping("/drugCompany/selectone/{id}")
    public Msg test02(@PathVariable Long id){
        Msg msg = drugCompanyService.selectOneDrugCompany(id);
        return msg;
    }

    @PostMapping("/drugCompany/getsome/{page}/{limit}")
    public Msg getSomeDrugCompany(@PathVariable Integer page, @PathVariable Integer limit,@RequestBody(required = false) DrugCompany teacherQuery){
        teacherQuery.setPn(page);
        teacherQuery.setSize(limit);
        Msg msg = drugCompanyService.getSomeDrugCompany(teacherQuery);
        return msg;
    }

    @PostMapping("/drugCompany/add")
    public Msg addDrugCompany(@RequestBody(required = false) DrugCompany drugCompany){
        Msg msg = drugCompanyService.insertDrugCompany(drugCompany);
        return msg;
    }

    @DeleteMapping("/drugCompany/delete")
    public Msg deleteDrugCompany(@RequestBody(required = false) String companyName){
//        System.out.println("====="+companyName);
        Msg msg = drugCompanyService.deleteDrugCompany(companyName);
        return msg;
    }

    @PostMapping("/drugCompany/update")
    public Msg updateDrugCompany(@RequestBody(required = false) DrugCompany drugCompany){
        System.out.println(drugCompany);
        Msg msg = drugCompanyService.updateDrugCompany(drugCompany);
        return msg;
    }
}
